<html debug="true">
<head>
  <title>Gears DBLib - Examples / Tests</title>
  <script src="../firebug/firebug.js" type="text/javascript"></script>
  <script src="../scripts/gears_db.js" type="text/javascript"></script>
  <script src="../scripts/tests_setup.js" type="text/javascript"></script>
  <script type="text/javascript">
  window.onload = function() {
    initDb();
  
    var db = new GearsDB('gears-test');
    
    var bob = {id: 3, name: 'Bob', url: 'http://bob.com', description: 'whee'};
    db.insertRow('person', bob);
    db.insertRow('person', bob, 'name = ?', ['Bob']);

    db.selectAll('select * from person', null, function(person) {
       document.getElementById('selectAll').innerHTML += ' ' + person.name;
    });

    db.selectRows('person', 'name like ?', ['%'], function(person) {
       document.getElementById('selectRows').innerHTML += ' ' + person.name;
    });
  
    var person = db.selectRow('person', 'id = 1');
    document.getElementById('selectRow').innerHTML = person.name;  
    
    // update
    person.name = 'Harry';
    db.updateRow('person', person);
    person = db.selectRow('person', 'id = 1');
    document.getElementById('updateRow').innerHTML = person.name;

    // force
    person.name = 'Sally';
    db.forceRow('person', person);
    person = db.selectRow('person', 'id = 1');
    document.getElementById('forceRow').innerHTML = person.name;

    var adam = {name: 'Adam', url: 'http://adam.com', description: 'long hair'};
    db.forceRow('person', adam);
    person = db.selectRow('person', 'id = 4');
    document.getElementById('forceRow2').innerHTML = person.name;
    
    db.deleteRow('person', bob);
    
    var all = db.selectAll('select * from person order by name');
    for (var i = 0; i < all.length; i++) {
      document.getElementById('selectAll2').innerHTML += ' ' + all[i].name;
    }
  }
  </script>
  <style type="text/css">
  div {
    color: #666;
    padding: 4px;
    background-color: yellow;
    border: 1px solid grey;
  }
  </style>
</head>
<body>
  
  <h1>Full Test Source</h1>
  <pre>
    var db = new GearsDB('gears-test');
    
    var bob = {id: 3, name: 'Bob', url: 'http://bob.com', description: 'whee'};
    db.insertRow('person', bob);
    db.insertRow('person', bob, 'name = ?', ['Bob']);

    db.selectAll('select * from person', null, function(person) {
       document.getElementById('selectAll').innerHTML += ' ' + person.name;
    });

    db.selectRows('person', 'name like ?', ['%'], function(person) {
       document.getElementById('selectRows').innerHTML += ' ' + person.name;
    });
  
    var person = db.selectRow('person', 'id = 1');
    document.getElementById('selectRow').innerHTML = person.name;  
    
    // update
    person.name = 'Harry';
    db.updateRow('person', person);
    person = db.selectRow('person', 'id = 1');
    document.getElementById('updateRow').innerHTML = person.name;

    // force
    person.name = 'Sally';
    db.forceRow('person', person);
    person = db.selectRow('person', 'id = 1');
    document.getElementById('forceRow').innerHTML = person.name;

    var adam = {name: 'Adam', url: 'http://adam.com', description: 'long hair'};
    db.forceRow('person', adam);
    person = db.selectRow('person', 'id = 4');
    document.getElementById('forceRow2').innerHTML = person.name;
    
    db.deleteRow('person', bob);
    
    var all = db.selectAll('select * from person order by name');
    for (var i = 0; i &lt; all.length; i++) {
      document.getElementById('selectAll2').innerHTML += ' ' + all[i].name;
    }
    
  </pre>
  
  <hr noshade="true" />
  
  <h1>Running Test Output</h1>
  
  <h3>selectAll</h3>
  <pre>
    db.selectAll('select * from person', null, function(person) {
       document.getElementById('selectAll').innerHTML += ' ' + person.name;
    });
  </pre>
  <div id="selectAll"></div>
  
  <h3>selectAll (not callback, not recommended)</h3>
  <pre>
    var all = db.selectAll('select * from person order by name');
    for (var i = 0; i &lt; all.length; i++) {
      document.getElementById('selectAll2').innerHTML += ' ' + all[i].name;
    }
  </pre>
  <div id="selectAll2"></div>  
  
  <h3>selectRows</h3>
  <pre>
    db.selectRows('person', 'name like ?', ['%'], function(person) {
       document.getElementById('selectRows').innerHTML += ' ' + person.name;
    });
  </pre>  
  <div id="selectRows"></div>
  
  <h3>selectRow</h3>
  <pre>
    var person = db.selectRow('person', 'id = 1');
  </pre>
  <div id="selectRow"></div>

  <h3>updateRow</h3>
  <pre>
    person = db.updateRow('person', person);
  </pre>
  <div id="updateRow"></div>

  <h3>forceRow</h3>
  <pre>
    person = db.forceRow('person', person);
  </pre>
  <div id="forceRow"></div>

  <pre>
    person = db.forceRow('person', person);
  </pre>
  <div id="forceRow2"></div>

</body>
</html>